﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Threading;
using System.Globalization;
using System.Text.RegularExpressions;
using Nivdal.TBP;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class TournamentGroup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();

            string GroupId = "";
            if (Request.QueryString["Id"] != null)
                GroupId = Request.QueryString["Id"];
            else
                Response.Redirect("~/TeamHomePage.aspx");

            string PageTitle = GND.ReadNivdalStringData("GroupId", "GroupTitle", "Nivdal_GetTournamentGroupName", GroupId, Resources.Resource.Tournament_Group);

            Title = Resources.Resource.Default_PageTitle + ", " + PageTitle;
            PageNameLabel.Text = PageTitle;
            PageTitleLink.Text = PageTitle;
            PageTitleLink.NavigateUrl = "~/Tournament.aspx?Id=" +
                GND.ReadNivdalIntData("GroupId", "Nivdal_GetTournamentIdByGroupId", GroupId);

            if (!IsPostBack)
            {
                RoundsDataSource.SelectParameters.Add("GroupId", GroupId);
                RoundsDataSource.SelectParameters.Add("Order", "0");
                TableDataSource.SelectParameters.Add("GroupId", GroupId);
                GroupIdHiddenField.Value = GroupId;
                NationalTeamsHiddenField.Value = GND.ReadNivdalBoolData("GroupId", "Nivdal_GetTournamentNationalTeamsByGroupId", GroupId) ? "1": "0";
            }
                
        }

        protected bool IsNationalTeams()
        {
            return (NationalTeamsHiddenField.Value == "1");
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}